package com.yupi.yangoj.judge;

import com.yupi.yangoj.judge.strategy.DefaultJudgeStrategy;
import com.yupi.yangoj.judge.strategy.JavaLanguageJudgeStrategy;
import com.yupi.yangoj.judge.strategy.JudgeContext;
import com.yupi.yangoj.judge.strategy.JudgeStrategy;
import com.yupi.yangoj.judge.codesandbox.model.JudgeInfo;
import com.yupi.yangoj.model.entity.QuestionSubmit;
import org.springframework.stereotype.Service;

/**
 * 策略设计模式：调用此类，选择一个具体的判题策略
 */
@Service
public class JudgeManager {

    /**
     * 执行判题
     * @param judgeContext  判题所需信息
     * @return
     */
    public JudgeInfo doJudge(JudgeContext judgeContext){
        QuestionSubmit questionSubmit = judgeContext.getQuestionSubmit();
        String language = questionSubmit.getLanguage();
        JudgeStrategy judgeStrategy = new DefaultJudgeStrategy();   //默认判题策略
        if ("java".equals(language)){
            //修改判题策略为java判题策略
            judgeStrategy = new JavaLanguageJudgeStrategy();
        }
        //todo 这里可以加入判断其他的判题策略，此处只写了java

        return judgeStrategy.doJudge(judgeContext);
    }
}
